﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QuanLyChoVay
{
    public partial class frmQuanLyNguoiDung : Form
    {
        public frmQuanLyNguoiDung()
        {
            InitializeComponent();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            {
                SqlCommand cmd = new SqlCommand();
                string tenBang = "";
                switch (comboBox1.SelectedIndex)
                {
                    case 0: tenBang = "ThongTinKhachHang"; break;
                    case 1: tenBang = "HopDongVay"; break;
                    case 2: tenBang = "nhanvien"; break;

                }
                cmd.CommandText = "select * from " + tenBang;
                cmd.Connection = new connect().getconnect();
                SqlDataReader rd;
                rd = cmd.ExecuteReader();
                if (rd != null)
                {
                    DataTable dt = new DataTable();
                    dt.Load(rd);
                    dataGridView1.DataSource = dt;
                }
            }
        }

        private void txttimkiem_TextChanged(object sender, EventArgs e)
        {
           // SqlCommand cmd = new SqlCommand();
            if (comboBox1.Text == "Quản lý Nhân viên") {

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = new connect().getconnect();
                cmd.CommandText = "select * from nhanvien where TenNhanVien like '%" + txttimkiem.Text + "%'";

                SqlDataReader rd;
                DataTable dt = new DataTable();
                rd = cmd.ExecuteReader();
                dt.Load(rd);
                dataGridView1.DataSource = dt;
            
            }
            else if (comboBox1.Text == "Quản lý Khách hàng")
            {

                SqlCommand cmd = new SqlCommand();
                cmd.Connection = new connect().getconnect();
                cmd.CommandText = "select * from ThongTinKhachHang where TenKhachHang like '%" + txttimkiem.Text + "%'";
                SqlDataReader rd;
                DataTable dt = new DataTable();
                rd = cmd.ExecuteReader();
                dt.Load(rd);
                dataGridView1.DataSource = dt;
            }
            else {
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = new connect().getconnect();
                cmd.CommandText = "select * from HopDongVay where KhoanVayYeuCau like '%" + txttimkiem.Text + "%'";
                SqlDataReader rd;
                DataTable dt = new DataTable();
                rd = cmd.ExecuteReader();
                dt.Load(rd);
                dataGridView1.DataSource = dt;
            }

        }
    }
}
